package controller;

import service.AtmService;
import util.MySpring;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Query extends HttpServlet {
    AtmService atmService = MySpring.getBean("service.AtmService");
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Query.service");
        String name4 = req.getParameter("name3");
        Float inquiry = atmService.inquiry(name4);
        resp.setCharacterEncoding("UTF-8");
        PrintWriter out = resp.getWriter();
        out.write("<html>");
        out.write(" <head>");
        out.write("     <meta charset=\"UTF-8\">");
        out.write("     <script type=\"text/javascript\">");
        out.write("         window.onload=function(){");
        out.write("             var inputElement = document.getElementById(\"back\");");
        out.write("             inputElement.onclick=function(){");
        out.write("                 window.history.back();");
        out.write("             }");
        out.write("         }");
        out.write("     </script>");
        out.write(" </head>");
        out.write(" <body>");
        out.write("     尊敬的"+name4+"您的可用余额为:"+inquiry+"<br>");
        out.write("     <input id=\"back\" type=\"button\" value=\"回去\">");
        out.write(" </body>");
        out.write("</html>");
        out.flush();
    }
}
